﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;


namespace Jemgine.MapEditor.Operations
{
	internal class ModifyTexturing : Operation
	{
        Engine.Selection Owner;
        Data.AlignableTexture Polygon;
        Data.TextureAlignment NewValue;
        Data.TextureAlignment OldValue;

        internal ModifyTexturing(Engine.Selection Owner, Data.TextureAlignment NewValue)
        {
            this.Owner = Owner;
            this.NewValue = NewValue;
        }

        internal override ReturnCode Do(EditorState ES)
        {
            Polygon = ES.GetMiddleObject(Owner) as Data.AlignableTexture;
            if (Polygon != null)
            {
                OldValue = Polygon.Alignment;
                Polygon.Alignment = new Data.TextureAlignment
                    {
                        Angle = OldValue.Angle + NewValue.Angle,
                        Offset = OldValue.Offset + NewValue.Offset,
                        Scale = OldValue.Scale + NewValue.Scale
                    };
                return ReturnCode.AddToUndoStack;
            }

            return ReturnCode.DoNotAddToUndoStack;
        }

        internal override void Undo(EditorState ES)
        {
            Polygon.Alignment = OldValue;
        }
	}
}
